//
//  LGServiceOrderView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/28.
//

#import "LGServiceOrderView.h"

@interface LGServiceOrderView()
/**   */
@property (nonatomic , strong)UIButton *titleBtn;
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *contentLabel1;
/**   */
@property (nonatomic , strong)UILabel *contentLabel2;
/**   */
@property (nonatomic , strong)UILabel *contentLabel3;
/**   */
@property (nonatomic , strong)UILabel *contentLabel4;

@end

@implementation LGServiceOrderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setType:(NSString *)type{
    _type = type;
    if([self.type isEqualToString:@"sevice"]){
        //服务包信息
        [self.titleBtn setTitle:@"服务包信息" forState:UIControlStateNormal];
        [self.titleBtn setImage:[UIImage imageNamed:@"订单详情-服务包信息"] forState:UIControlStateNormal];
        
    }else if ([self.type isEqualToString:@"order"]){
        //订单信息
        [self.titleBtn setTitle:@"订单信息" forState:UIControlStateNormal];
        [self.titleBtn setImage:[UIImage imageNamed:@"订单详情-订单信息"] forState:UIControlStateNormal];
        [self.baseView  addSubview:self.contentLabel4];
        [self.contentLabel4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentLabel3.mas_bottom).offset(viewPix(15));
            make.left.right.equalTo(self.contentLabel1);
        }];
        
    }else if ([self.type isEqualToString:@"refund"]){
        //退款信息
        [self.titleBtn setTitle:@"退款信息" forState:UIControlStateNormal];
        [self.titleBtn setImage:[UIImage imageNamed:@"订单详情-退款信息"] forState:UIControlStateNormal];
    }
   
}


-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    if([self.type isEqualToString:@"sevice"]){
        //服务包信息
        self.contentLabel1.attributedText = [self attributeString:@"价格" content:[NSString stringWithFormat:@"       %@ 元/年",dataDic[@"price"]]];
        self.contentLabel2.attributedText = [self attributeString:@"服务医生" content:dataDic[@"doctorname"]];
        self.contentLabel3.attributedText = [self attributeString:@"服务团队" content:dataDic[@"teamname"]];
        
    }else if ([self.type isEqualToString:@"order"]){
        //订单信息
        self.contentLabel1.attributedText = [self attributeString:@"订单编号" content:dataDic[@"orderno"]];
        self.contentLabel2.attributedText = [self attributeString:@"订单时间" content:dataDic[@"ordertime"]];
        self.contentLabel3.attributedText = [self attributeString:@"支付金额" content:[NSString stringWithFormat:@"%@ 元",dataDic[@"price"]]];
        self.contentLabel4.attributedText = [self attributeString:@"支付时间" content:dataDic[@"ordertime"]];
        
    }else if ([self.type isEqualToString:@"refund"]){
        //退款信息
        self.contentLabel1.attributedText = [self attributeString:@"退款原因" content:dataDic[@"refuned_desc"]];
        self.contentLabel2.attributedText = [self attributeString:@"退款金额" content:[NSString stringWithFormat:@"%@ 元",dataDic[@"refuned_fee"]]];
        self.contentLabel3.attributedText = [self attributeString:@"退款时间" content:dataDic[@"refuned_date"]];
    }
}

-(NSMutableAttributedString *)attributeString:(NSString *)title  content:(NSString *)content{
    NSString *tempString = [NSString stringWithFormat:@"%@   %@",title,content];
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:tempString];
    [attStr addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(title.length, tempString.length-title.length)];
    return attStr;
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self addSubview:self.titleBtn];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.contentLabel1];
    [self.baseView  addSubview:self.contentLabel2];
    [self.baseView  addSubview:self.contentLabel3];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(viewPix(45));
        make.left.equalTo(self).offset(viewPix(12));
        make.right.bottom.equalTo(self).offset(-viewPix(12));
    }];
    [self.contentLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.baseView).offset(viewPix(8));
        make.right.equalTo(self.baseView).offset(-viewPix(8));
    }];
    [self.contentLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel1.mas_bottom).offset(viewPix(15));
        make.left.right.equalTo(self.contentLabel1);
    }];
    [self.contentLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel2.mas_bottom).offset(viewPix(15));
        make.left.right.equalTo(self.contentLabel1);
    }];
}
-(UIButton *)titleBtn{
    if(!_titleBtn){
        _titleBtn = [UIButton buttonWithTitle:@"" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#333333" imageName:@""];
        _titleBtn.frame = CGRectMake(viewPix(16), viewPix(12), viewPix(120), viewPix(22));
        _titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _titleBtn;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc]init];
        _baseView.backgroundColor  = [UIColor colorWithString:@"#F7F9FB"];
        _baseView.cornerRidus = 5;
    }
    return _baseView;
}

-(UILabel *)contentLabel1{
    if(!_contentLabel1){
        _contentLabel1 = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _contentLabel1;
}

-(UILabel *)contentLabel2{
    if(!_contentLabel2){
        _contentLabel2 = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _contentLabel2;
}

-(UILabel *)contentLabel3{
    if(!_contentLabel3){
        _contentLabel3 = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _contentLabel3;
}

-(UILabel *)contentLabel4{
    if(!_contentLabel4){
        _contentLabel4 = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _contentLabel4;
}




@end
